package com.jack.submeiju.database;

import java.sql.DriverManager;
import java.sql.SQLException;

import com.jack.etc.DatabaseConfig;
import com.mysql.jdbc.Connection;

public class ConnectionManager {

	// private static Connection conn = null;
	private static String url = null;
	private static String username = null;
	private static String password = null;

	private ConnectionManager() {
	}

	public static void initConnectionManager(String url, String username,
			String password) {
		ConnectionManager.url = url;
		ConnectionManager.username = username;
		ConnectionManager.password = password;
	}

	public static Connection getSqlConnnection() {
		Connection conn = null;
		try {
			Class.forName(DatabaseConfig.dbDriverName);
			conn = (Connection) DriverManager.getConnection(url, username,
					password);
		} catch (SQLException se) {
			System.out.println("数据库连接失败！");
			se.printStackTrace();
			conn = null;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			conn = null;
		}
		return conn;
	}

}
